using UnityEngine;
using UnityEngine.UI;

public class UIManager : MonoBehaviour
{
    public int stoneNum;//石头资源数量
    public Text stoneText;//石头资源文本
    public static UIManager Instance { get; private set; }
    public Button buildButton1;
    public Button buildButton2;
    public Button buildButton3;
    public GameObject buildObject1;
    public GameObject buildObject2;
    public GameObject buildObject3;
    public GameObject tipsObj;
    void Awake()
    {
        Instance = this;
    }

    void Start()
    {
        stoneText.text = "石头资源：" + stoneNum;
        buildButton1.onClick.AddListener(OnBtnBuild1);
        buildButton2.onClick.AddListener(OnBtnBuild2);
        buildButton3.onClick.AddListener(OnBtnBuild3);

    }

    public void AddStoneNum(int num)
    {
        stoneNum += num;
        stoneText.text = "石头资源：" + stoneNum;
    }

    void OnBtnBuild1()
    {
        if (stoneNum < buildObject1.GetComponent<Buildable>().useNum)
        {
            SetTips("资源不足");
            return;
        }
        BuildManager.Instance.SelectBuilding(buildObject1);
    }
    void OnBtnBuild2()
    {
        if (stoneNum < buildObject2.GetComponent<Buildable>().useNum)
        {
            SetTips("资源不足");
            return;
        }
        BuildManager.Instance.SelectBuilding(buildObject2);
    }
    void OnBtnBuild3()
    {
        if (stoneNum < buildObject3.GetComponent<Buildable>().useNum)
        {
            SetTips("资源不足");
            return;
        }
        BuildManager.Instance.SelectBuilding(buildObject3);
    }

    public void SetTips(string str)
    {
        GameObject obj = Instantiate(tipsObj, transform);
        obj.GetComponent<Text>().text = str;
    }
}